home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / keyboard / inpreal.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  9.5 KB  |  303 lines

  1. ;void  input_real(col,row,color,max_left,max_right,return_string);
  2. ;  unsigned short  col,row,color,max_left,max_right,;
  3. ;  char *return_string;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _beep_on:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _input_real
  11. _input_real proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set up stack pointer
  14.     push di            ;
  15.     push si            ;
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bp            ;else add 2 to BP
  19.     inc  bp            ;
  20. begin:    cmp  _memory_model,2    ;data near or far?
  21.     jb   L0            ;jump if near
  22.     les  si,dword ptr[bp+14]  ;get ptr to return string
  23.     jmp  short L00        ;
  24. L0:    mov  ax,ds        ;ES = DS
  25.     mov  es,ax        ;
  26.     mov  si,[bp+14]        ;
  27. L00:    mov  byte ptr es:[si],0    ;set NumStrg descriptor
  28.     mov  dl,[bp+4]        ;column in DL
  29.     dec  dl            ;count from 0
  30.     cmp  dl,79        ;in range?
  31.     jna  B1            ;jump ahead if not
  32. A1:    jmp  L2            ;else quit
  33. B1:    mov  dh,[bp+6]        ;row in DH
  34.     dec  dh            ;count from 0
  35.     cmp  dh,24        ;in range?
  36.     ja   A1            ;quit if so
  37.     mov  cx,[bp+12]        ;MaxRight to CX
  38.     push CX            ;push on to stack
  39.     sub  cx,cx        ;0 = current rightlen
  40.     push cx            ;push on to stack
  41.     sub  bh,bh        ;select page 0
  42.     mov  bl,[bp+8]        ;attribute in BL
  43.     mov  al,[bp+10]        ;MaxLeft to AL
  44.     sub  ah,ah        ;clear AH
  45.     mov  di,ax        ;store MaxLeft in DI
  46.     sub  bp,bp        ;current leftlen in BP
  47.     mov  ah,2        ;function to set cursor
  48.     int  10h        ;set cursor
  49.     mov  ah,9        ;function to write char
  50.     mov  al,'.'        ;will write decimal point
  51.     mov  cx,1        ;number chars to write
  52.     int  10h        ;write the decimal point
  53.     mov  ah,2        ;function to set cursor
  54.     dec  dl            ;cursor 1 col to left
  55.     int  10h        ;set the cursor
  56. C1:    sub  ah,ah        ;func to read keystroke
  57.     int  16h        ;wait for keystroke
  58.     or   al,al        ;test for extended code
  59.     jnz  D1            ;jump if not extended
  60.     cmp  ah,83        ;is it the delete key?
  61.     jne  C1            ;next keystroke if not
  62.     jmp  L1            ;else jump to delete code
  63. D1:    cmp  al,8        ;is it the backspace?
  64.     jne  E1            ;jump ahead if not
  65.     jmp  L1            ;else go to delete code
  66. E1:    cmp  al,13        ;chk for carriage return
  67.     jne  F1            ;jump ahead if not
  68.     jmp  K2            ;else go to CR code
  69. F1:    cmp  al,'.'        ;chk for decimal point
  70.     jne  G1            ;jump ahead if not
  71.     jmp  Q1            ;else go to decimal code
  72. G1:    cmp  al,'-'        ;chk for minus sign
  73.     jne  H1            ;jump ahead if not
  74.     or   bp,bp        ;current leftlen 0?
  75.     jnz  C1            ;new keystroke if not
  76.     inc  di            ;inc MaxLeft counter
  77.     jmp  I1            ;go write it
  78. H1:    cmp  al,'0'        ;below '0' char?
  79.     jb   C1            ;get another keystroke
  80.     cmp  al,'9'        ;above '9' char?
  81.     ja   C1            ;get another keystroke
  82.     cmp  bp,di        ;cmp leftlen to max
  83.     jb   I1            ;jump ahead if not full
  84.     push dx            ;keep cursor position
  85.     mov  ah,2        ;DOS func to write char
  86.     mov  dl,7        ;bell character
  87.     cmp  _beep_on,0        ;test if beep enabled
  88.     je   H3            ;jump if not
  89.     int  21h        ;beep!
  90. H3:    pop  dx            ;restore cursor position
  91.     jmp  short C1        ;go get another keystroke
  92. I1:    inc  bp            ;inc current leftlen
  93.     cmp  bp,1        ;only 1 char?
  94.     je   K1            ;no char shift if so
  95.     push ax            ;save new keystroke
  96.     mov  cx,bp        ;current leftlen to CX
  97.     dec  cx            ;count from 0
  98.     sub  dl,cl        ;shift curs to lft char+1
  99. J1:    inc  dl            ;cursor back 1 to right
  100.     mov  ah,2        ;func to set cursor
  101.     int  10h        ;set the cursor
  102.     mov  ah,8        ;func reads cursor char
  103.     int  10h        ;read the char
  104.     push ax            ;save char
  105.     dec  dl            ;shift cursor 1 col left
  106.     mov  ah,2        ;function to set cursor
  107.     int  10h        ;set the cursor
  108.     pop  ax            ;restore char
  109.     push cx            ;keep counter in CX
  110.     mov  ah,9        ;function to write char
  111.     mov  cx,1        ;number chars to write
  112.     int  10h        ;write the char
  113.     pop  cx            ;restore counter
  114.     inc  dl            ;cursor right 1 col
  115.     loop J1            ;go shift next
  116.     mov  ah,2        ;func to set cursor
  117.     int  10h        ;set the cursor
  118.     pop  ax            ;restore new keystroke
  119. K1:    mov  ah,9        ;function to write char
  120.     mov  cx,1        ;number chars to write
  121.     int  10h        ;write the char in AL
  122.     mov  cl,1        ;increment value
  123.     add  es:[si],cl        ;inc NumStrg descriptor
  124.     mov  es:[si][bp],al    ;write char to NumStrg
  125.     jmp  C1            ;go get next keystroke
  126. L1:    or   bp,bp        ;DELETE: none to delete?
  127.     jnz  M1            ;jump ahead if not
  128.     jmp  C1            ;ignor, next keystroke
  129. M1:    push dx            ;save cursor position
  130.     dec  bp            ;dec current leftlen
  131.     push bp            ;save current leftlen
  132.     or   bp,bp        ;test for 0 len
  133.     jnz  O1            ;if not 0, shift chars
  134.     mov  al,'-'        ;1 char, test if '-'
  135.     cmp  es:[si+1],al    ;chk 1st char in string
  136.     jne  N1            ;jump ahead if not '-'
  137.     dec  di            ;else dec MaxLeft ctr
  138. N1:    jmp  P1            ;skip char shift when 0
  139. O1:    dec  dl            ;move cursor 1 col left
  140.     mov  ah,2        ;function to set cursor
  141.     int  10h        ;set the cursor
  142.     mov  ah,8        ;func reads char at curs
  143.     int  10h        ;read the char
  144.     push ax            ;save the char
  145.     inc  dl            ;move cursor 1 col right
  146.     mov  ah,2        ;function to set cursor
  147.     int  10h        ;set the cursor
  148.     pop  ax            ;restore the char
  149.     mov  ah,9        ;func to write a char
  150.     mov  cx,1        ;number chars to write
  151.     int  10h        ;write the char
  152.     dec  dl            ;move cursor 1 col left
  153.     dec  bp            ;dec str len counter
  154.     cmp  bp,0        ;finished shifting chars?
  155.     jne  O1            ;loop if not
  156.     mov  ah,2        ;func to set cursor
  157.     int  10h        ;set the cursor
  158. P1:    mov  al,' '        ;write space char
  159.     mov  ah,9        ;function to write char
  160.     int  10h        ;erase leftmost char
  161.     pop  bp            ;restore current leftlen
  162.     pop  dx            ;restore cursor position
  163.     mov  ah,2        ;func to set cursor
  164.     int  10h        ;set cursor
  165.     mov  cl,1        ;decrement value
  166.     sub  es:[si],cl        ;dec ret str descriptor
  167.     jmp  C1            ;go get next keystroke
  168. Q1:    pop  ax            ;pop (dummy) current len
  169.     pop  cx            ;pop max rightlen
  170.     push di            ;save max leftlen
  171.     push bp            ;save current leftlen
  172.     mov  di,bp        ;current leftlen to DI
  173.     add  di,cx        ;add max rightlen
  174.     inc  bp            ;inc current len '.'
  175.     inc  di            ;inc max len for '.'
  176.     mov  cl,1        ;increment for strg len
  177.     add  es:[si],cl        ;inc NumStrg descriptor
  178.     mov  al,'.'        ;prepare to write '.'
  179.     mov  es:[si][bp],al    ;add '.' to NumStrg
  180.     add  dl,2        ;cursor 2 cols to right
  181.     mov  ah,2        ;func to set cursor
  182.     int  10h        ;set the cursor
  183.     sub  cx,cx        ;clear CX for flags
  184. R1:    sub  ah,ah        ;func to read keystroke
  185.     int  16h        ;wait for a keystroke
  186.     cmp  al,0        ;test for extended code
  187.     jnz  S1            ;jump if not extended
  188.     cmp  ah,83        ;test for delete key
  189.     je   A2            ;jump to backspace code
  190.     jmp  short R1        ;get another keystroke
  191. S1:    cmp  al,13        ;is it a carriage return?
  192.     jne  T1            ;jump ahead if not
  193.     jmp  K2            ;else quit routine
  194. T1:    cmp  al,'e'        ;test for 'e'
  195.     jne  V1            ;jump ahead if not 'e'
  196. U1:    or   cl,cl        ;test CL (1 = already e)
  197.     jnz  R1            ;discard if CX = 1
  198.     mov  cl,1        ;set flag in CL
  199.     jmp  short I2        ;go write the char
  200. V1:    cmp  al,'E'        ;test for 'E'
  201.     jne  W1            ;jump ahead if not 'E'
  202.     jmp  short U1        ;else go test flag
  203. W1:    cmp  al,'+'        ;test for '+'
  204.     jne  Y1            ;jump if not '+'
  205. X1:    or   cl,cl        ;test if 'e' written
  206.     jz   R1            ;new keystroke if not
  207.     or   ch,ch        ;test if +/- written
  208.     jnz  R1            ;new keystroke if so
  209.     mov  ch,1        ;set flag +/- written
  210.     jmp  short I2        ;go write the char
  211. Y1:    cmp  al,'-'        ;test for '-'
  212.     jne  Z1            ;jump if not '-'
  213.     jmp  short X1        ;go test flags
  214. Z1:    cmp  al,8        ;test for backspace
  215.     jne  H2            ;jump ahead if not
  216. A2:    mov  al,'.'        ;seek '.' in NumStrg
  217.     mov  ah,es:[si][bp]    ;get char in NumStrg
  218.     cmp  ah,al        ;is it '.'?
  219.     jne  B2            ;jump ahead if not
  220.     sub  dl,2        ;cursor 2 cols to left
  221.     mov  ah,2        ;function to set cursor
  222.     int  10h        ;reset cursor
  223.     pop  bp            ;current leftlen to BP
  224.     pop  cx            ;max leftlen to CX
  225.     sub  di,bp        ;calc prior maxleft
  226.     dec  di            ;minus one for decimal
  227.     push di            ;save as max rightlen
  228.     push di            ;push dummy value
  229.     mov  di,cx        ;move max leftlen to DI
  230.     mov  al,1        ;number to dec
  231.     sub  es:[si],al        ;dec descriptor for '.'
  232.     jmp  L1            ;switch to left side code
  233. B2:    cmp  ah,'+'        ;erasing '+'?
  234.     jne  C2            ;jump if not
  235.     sub  ch,ch        ;clear flag
  236. C2:    cmp  ah,'-'        ;erasing '-'?
  237.     jne  D2            ;jump if not
  238.     sub  ch,ch        ;clear flag
  239. D2:    cmp  ah,'e'        ;erasing 'e'?
  240.     jne  E2            ;jump if not
  241.     sub  cl,cl        ;clear flag
  242. E2:    cmp  ah,'E'        ;erasing 'E'?
  243.     jne  F2            ;jump if not
  244.     sub  cl,cl        ;clear flag
  245. F2:    dec  dl            ;cursor 1 col to left
  246.     mov  ah,2        ;function to set cursor
  247.     int  10h        ;reset the cursor
  248.     mov  al,' '        ;space char for erasure
  249.     mov  ah,9        ;function to write char
  250.     push cx            ;save flags in CX
  251.     mov  cx,1        ;num chars to write
  252.     int  10h        ;erase end character
  253.     dec  bp            ;dec current str len
  254.     sub  es:[si],cl        ;dec NumStrg descriptor
  255.     pop  cx            ;restore flags
  256. G2:    jmp  R1            ;go get next keystroke
  257. H2:    cmp  al,'0'        ;test if char < '0'
  258.     jb   G2            ;new keystroke if below
  259.     cmp  al,'9'        ;test if char > '9'
  260.     ja   G2            ;new keystroke if above
  261. I2:    cmp  di,bp        ;compare current/max lens
  262.     jne  J2            ;proceed if not equal
  263.     push dx            ;else save DX
  264.     mov  ah,2        ;DOS func to write char
  265.     mov  dl,7        ;bell character to DL
  266.     cmp  _beep_on,0        ;test whether beep enabled
  267.     je   I3            ;jump ahead if not
  268.     int  21h        ;beep!
  269. I3:    pop  dx            ;restore DX
  270.     jmp  R1            ;go get another keystroke
  271. J2:    mov  ah,9        ;function to write char
  272.     push cx            ;save flags in CX
  273.     mov  cx,1        ;number chars to write
  274.     int  10h        ;write the character
  275.     add  es:[si],cl        ;inc NumStrg descriptor
  276.     pop  cx            ;restore flags in CX
  277.     inc  bp            ;inc current len ctr
  278.     mov  es:[si][bp],al    ;write char to NumStrg
  279.     inc  dl            ;cursor 1 col to right
  280.     mov  ah,2        ;function to set cursor
  281.     int  10h        ;reset the cursor
  282.     jmp  R1            ;go get next keystroke
  283. K2:    pop  cx            ;balance stack
  284.     pop  cx            ;
  285. L2:    sub  cx,cx        ;change to C string
  286.     mov  cl,es:[si]        ;get string length
  287.     jcxz N2            ;quit if null
  288. M2:    inc  si            ;
  289.     mov  al,es:[si]        ;
  290.     mov  es:[si-1],al    ;
  291.     loop M2            ;
  292.     mov  byte ptr es:[si],0    ;null terminator
  293. N2:    pop  si            ;
  294.     pop  di            ;
  295.     pop  bp            ;
  296.     cmp  _memory_model,0    ;quit
  297.     jle  quit        ;
  298.     db   0CBh        ;RET far
  299. quit:    ret            ;RET near
  300. _input_real ENDP
  301. _TEXT    ENDS
  302.     END
  303.